import Vue from "vue";
import VueRouter from "vue-router";
import params from "@/core/api/params";



Vue.use(VueRouter);



const routes = [{
    path: "/",
    name: "home",
    component: () => import("@/views/Home.vue"),

    children: [{
        path: "index",
        component: () => import("@/components/index.vue"),
        meta: {
          title: "首页",
          uname: "yuxia",
          keepAlive:false
        }
      },
      {
        path: "list",
        name:"list",
        component: () => import("@/components/list.vue"),
        meta: {
          title: "列表页",
          uname: "yuxia"
        }
      },
      {
        path: "list/:num",
        name:"list",
        component: () => import("@/components/two.vue"),
        meta: {
          title: "列表页",
          uname: "yuxia"
        }
      },
      {
        path: "login",
        name: "login",
        component: () => import("@/components/login.vue"),
        meta: {
          title: "登录页",
        }
      },
      {
        path: "testv",
        name: "testv",
        component: () => import("@/components/testv.vue"),
        meta: {
          title: "Vuex测试1",
        }
      },
      {
        path: "testt",
        name: "testt",
        component: () => import("@/components/testt.vue"),
        meta: {
          title: "Vuex测试2",
        }
      },
      {
        path: "testx",
        name: "testx",
        component: () => import("@/components/testx.vue"),
        meta: {
          title: "Vuex测试3",
        }
      },
    ]
  }
  //     {
  //       path: "test",
  //       name:"test",
  //       component: () => import("@/components/test.vue"),
  //       meta:{
  //         title:"测试页",
  //         uname:"yuxia"
  //       }
  //     }
  //   ]
  //   // redirect:"/index"
  // },
  // {
  //   path: "/user",
  //   name: "user",
  //   component: () => import("@/views/user.vue"),
  //   children: [{
  //     path: "index",
  //     component: () => import("@/components/test.vue")
  //   }]
  //   // redirect:"/user/index"
  // }
];
const router = new VueRouter({
  // mode:"history",
  routes
});
router.beforeEach((to, from, next) => {
  if (to.path == "/") {
    if (params.userType === "index") {
      next({
        path: "/index"
      });
    } else if (params.userType === "list") {
      next({
        path: "/list"
      })
    } else if (params.userType === "test") {
      next({
        path: "/test"
      })
    }
  } else {
    next();
  }
});

export default router;